define(function(require) {
	var $ = require("jquery");
	var justep = require("$UI/system/lib/justep");
	
	var Model = function() {
	    this.current = -1;
	    this.toPath = '$UI/communityOto/mine/mineFragment.w';
	    this.currentPath = '';
	    this.user = {};
	    this.timer = -1;
	    this.serverUrl = "http://www.xjzlhy.com:81";
	    
		this.callParent();
	};

	Model.prototype.modelLoad = function(event){
		document.body.addEventListener("touchstart", function () { }); 
		
	};
	
	 Model.prototype.goTo = function(path){
	    
    	if(!localStorage.getItem("userInfo")){
    	    this.current = this.comp("body").getActiveIndex();
    	    this.toPath = path;
    		//this.comp("body").to(this.to); 
    		if(this.current === 0){
    		   
    		    this.currentPath = '$UI/communityOto/home/home.w';
    			this.comp('homeContainer').setSrc('$UI/communityOto/mine/login.w');
    			this.comp('homeContainer').refresh();
    		}else if(this.current === 1){
    		    this.currentPath = '$UI/communityOto/community/community.w';
    			this.comp('communityContainer').setSrc('$UI/communityOto/mine/login.w');
    			this.comp('communityContainer').refresh();
    		}else if (this.current === 3){
    			this.comp('mineContainer').setSrc('$UI/communityOto/mine/mineFragment.w');
    			this.comp('mineContainer').refresh();
    		}
	    }else{
	    	this.comp("contentDialog").open({src:path});
	    }
    };
    
    Model.prototype.goBackHome = function(){
       // var userInfo = localStorage.getItem("userInfo");
    	this.comp('homeContainer').setSrc('$UI/communityOto/home/home.w');
    	this.current = -1;
		this.comp('homeContainer').refresh();
		//this.comp('body').to(0);
    };
    
     Model.prototype.goBackCommunity = function(){
    
    	this.comp('communityContainer').setSrc('$UI/communityOto/community/community.w');
    	this.current = -1;
		this.comp('communityContainer').refresh();
		//this.comp('body').to(1);
    };
    
    Model.prototype.goBackLogin = function(){
        
    	this.comp('mineContainer').setSrc('$UI/communityOto/mine/login.w');
    	//$('.btn_back').hide();
    	this.current = -1;
		this.comp('mineContainer').refresh();
		
		//this.comp('body').to(3);
		
    };
    
    
	Model.prototype.userBtnClick = function(event){
		if(localStorage.getItem("userInfo")){
			this.comp('mineContainer').setSrc('$UI/communityOto/mine/mineFragment.w');
		    this.comp('mineContainer').refresh();
		   //this.comp('body').to(3);
		}else{
			$('.btn_back').hide();
		}
	};
	Model.prototype.homeContainerLoad = function(event){
	   
	    
		var data = JSON.parse(localStorage.getItem("userInfo"));
		if(data && data.userType == '4'){
		    $('.MerchantMall').show();
	    }
	    
	
       
	};
	Model.prototype.homeBtnClick = function(event){
	        if(this.comp("body").getActiveIndex() !== 0){
	        	this.comp('homeContainer').setSrc('$UI/communityOto/home/home.w');
	        	this.comp('homeContainer').refresh();
	        }
	    	
	    
	    
		if(this.current === 0 && localStorage.getItem("userInfo")){
			this.comp("contentDialog").open({src:this.toPath});
		}

	};
	Model.prototype.microBtnClick = function(event){
		this.comp('communityContainer').setSrc('$UI/communityOto/community/community.w');
		this.comp('communityContainer').refresh();
		if(this.current === 1 && localStorage.getItem("userInfo")){
			this.comp("contentDialog").open({src:this.toPath});
		}
	};
	Model.prototype.mineContainerLoad = function(event){
		$('.btn_back').hide();

	};
	
	
	//获取用户名称
	Model.prototype.getUserName = function(){
	
	    console.log(JSON.parse(localStorage.getItem("userInfo")));
		return JSON.parse(localStorage.getItem("userInfo")).userName;
	};

	
	//获取用户电话
	Model.prototype.getUserPhone = function(){
		return JSON.parse(localStorage.getItem("userInfo")).phone;
	};
	//获取用户地址
	Model.prototype.getUserAddress = function(){
		return JSON.parse(localStorage.getItem("companyInfo")).address;
	};
	
	//获取用户ID
	Model.prototype.getUserId = function(){    
		return JSON.parse(localStorage.getItem("userInfo")).userId;	
	};
	
	//获取社区名称
	Model.prototype.getCompanyName = function(){
	    //console.log(JSON.parse(localStorage.getItem("userInfo")).data[0].userId);
		return JSON.parse(localStorage.getItem("companyInfo")).name;
	
	};
	
	//获取社区ID
	Model.prototype.getCompanyId = function(){
	    return JSON.parse(localStorage.getItem('companyInfo')).id;		
	};
	
		
	//获取社区名称
	Model.prototype.getCompanyName = function(){
	    
	    //console.log(JSON.parse(localStorage.getItem("userInfo")).data[0].userId);
		return JSON.parse(localStorage.getItem("companyInfo")).name;
	
	};
	
	//获取社区地址
	Model.prototype.getCompanyAddress = function(){
	    //console.log(JSON.parse(localStorage.getItem("userInfo")).data[0].userId);
		return JSON.parse(localStorage.getItem("companyInfo")).address;
	
	};
	
	//获取社区邮编
	Model.prototype.getCompanyCode = function(){
	    //console.log(JSON.parse(localStorage.getItem("userInfo")).data[0].userId);
		return JSON.parse(localStorage.getItem("companyInfo")).code;
	
	};
	
	
	//获取小区ID
	Model.prototype.getOfficeId = function(){
	    //console.log(JSON.parse(localStorage.getItem("userInfo")).data[0].userId);
	    if(!localStorage.getItem("officeInfo")){
	    	return null;
	    }
		return JSON.parse(localStorage.getItem("officeInfo")).id;
	
	};
	
	
	
	Model.prototype.homeInactive = function(event){
	   
		clearInterval(this.timer);
		this.timer = -1;

	};
	
	Model.prototype.categoryContainerLoad = function(event){
		$('html').css({"overflow":"auto"});$('body').css({"overflow":"auto"});
		$('.mainMenu').css('height',$('body').innerHeight()-96);

	};
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	return Model;
});